import { Document, model, Schema } from 'mongoose'

export interface EmojiUsage extends Document {
  emoji: string
  roomId: string
  userId: string
  count: number
  lastUsed: Date
}

export const EmojiUsageSchema = new Schema({
  emoji: { type: String, required: true },
  roomId: { type: String, required: true },
  userId: { type: String, required: true },
  count: { type: Number, default: 1 },
  lastUsed: { type: Date, default: Date.now },
})

// 添加复合索引以优化查询性能
EmojiUsageSchema.index({ roomId: 1, emoji: 1 }, { unique: true })

// 注册模型
export const EmojiUsageModel = model<EmojiUsage>('EmojiUsage', EmojiUsageSchema)
